package logic

import (
	"context"
	"zhihu/zhihurpc/zhihurpcclient"

	"zhihu/api/internal/svc"
	"zhihu/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type ProblemAddLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewProblemAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ProblemAddLogic {
	return &ProblemAddLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *ProblemAddLogic) ProblemAdd(req *types.ProblemAddRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	register, err := l.svcCtx.Zhihurpc.ProblemAdd(l.ctx, &zhihurpcclient.ProblemAddRequest{
		Content: req.Content,
		UserId:  req.UserId,
		Hot:     req.Hot,
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Data:    nil,
			Code:    500,
		}, nil
	}
	return &types.Response{
		Message: "问题发布成功",
		Data:    register,
		Code:    200,
	}, nil
	return
}
